package fr.enseirb.webxml.servlet;

import java.util.Properties;
import java.util.HashMap;
import java.util.Map;

import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import java.util.Arrays;
import java.util.LinkedList;
import java.util.Properties;

import fr.enseirb.webxml.data.xml.XMLMediator;
import fr.enseirb.webxml.util.XMLToolkit;

import fr.enseirb.webxml.util.ServletToolkit;



/**
 * Servlet implementation class AboutServlet
 */
public class ListUsersServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;

	

	/**
	 * @see HttpServlet#HttpServlet()
	 */
	public ListUsersServlet() {
		super();
	}

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */

	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {	
	String URL = request.getRequestURI();

		
	if (URL.contains("xml"))
	{
		response.setHeader("Content-Type","application/xml");		
		String fluxXML = XMLMediator.getUsers();
		ServletToolkit.writeResponse(response,fluxXML);	

	}
	else
	{
		String html;
		String XSLPath = "resources/xsl/common/feuille.xsl";
		String fluxXML = XMLMediator.getUsers();
		Map<String, String> xslParams = new HashMap<String, String>();
		xslParams.put("pageTitle", "La liste des utilisateurs");
		xslParams.put("htmlTitle", "La liste des utilisateurs");
		html = XMLToolkit.transformXML(fluxXML, XSLPath, xslParams);
		ServletToolkit.writeResponse(response,html);
	}	
	}

	
}
